perf: FIT-1330: Fix O(n^2) config validation by using Map and Set lookups#9299
perf: FIT-1330: Fix O(n^2) config validation by using Map and Set lookups#9299
Conversation
The config validator was using O(n) flatTree.find() inside a loop, resulting in O(n²) complexity. With large configs (200+ tags), this caused noticeable delays during config validation. Changes: - validateToNameTag: Pre-build name->element Map for O(1) lookup - validateParentTag: Convert parentTypes to Set for O(1) has() check - validateVisualTags: Use module-level Set instead of inline array This reduces validation complexity from O(n²) to O(n).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9299 +/- ##
============================================
- Coverage 66.82% 56.04% -10.78%
============================================
Files 830 575 -255
Lines 64879 41460 -23419
Branches 10971 11465 +494
============================================
- Hits 43355 23238 -20117
+ Misses 21520 18218 -3302
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
✅ Deploy Preview for label-studio-docs-new-theme ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for label-studio-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for label-studio-playground ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for heartex-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Problem
validateToNameTag()inConfigValidator.jsiterates over all tags to find matching names, creating O(n^2) complexity when validating toName bindings. For 200+ tags, this causes noticeable initialization delays.Solution
Map<name, tag>during validation setupvalidateToNameTag()now accepts this map for O(1) lookupsvalidateParentTag()andvalidateVisualTags()with similar techniquesFiles Changed
web/libs/editor/src/core/DataValidator/ConfigValidator.jsJira
FIT-1330
Made with Cursor